//
//  ASNetworkEngine.h
//
//  Created by dfangjun on 16-2-14.
//  Copyright (c) dfangjun. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <Availability.h>
#import <MobileCoreServices/MobileCoreServices.h>

//#import "AFHTTPRequestOperation.h"
#import "AFURLResponseSerialization.h"
#import "AFURLRequestSerialization.h"
#import "AFSecurityPolicy.h"
#import "AFNetworkReachabilityManager.h"

@interface ASNetworkEngine : NSObject

//请求地址
@property (readonly, nonatomic, strong) NSURL *requestURL;

//请求序列化
//@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;

//返回系列化
//@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;

//请求队列
@property (nonatomic, strong) NSOperationQueue *operationQueue;

//网络判断
//@property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;


/**
 *  post 请求
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                      parameters:(id)parameters
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;

/**
 *  post 请求
 *
 *  @param URLString        请求地址
 *  @param headParameters   请求参数
 *  @param parameters       请求参数
 *  @param success          成功
 *  @param failure          失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                  headParameters:(id)parameters
                      parameters:(id)parameters
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;

/**
 *  post 请求
 *
 *  @param URLString      请求地址
 *  @param headParameters 请求头
 *  @param bodyParameters 请求体
 *  @param isBodyEncoding 请求体是否需要编码
 *  @param success        请求成功
 *  @param failure        请求失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                  headParameters:(id)headParameters
                  bodyParameters:(id)bodyParameters
                  isBodyEncoding:(BOOL)isBodyEncoding
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;


- (void)PUT:(NSString *)URLString
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

- (void)PUT:(NSString *)URLString
                 headParameters:(id)headParameters
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;
/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *
 *  @return 返回请求对象
 */
- (void)GET:(NSString *)URLString
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;


/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param headParameters 请求head设置
 *  @param parameters     请求参数
 *  @param success        成功
 *  @param failure        失败
 *
 *  @return 返回请求对象
 */

- (void)GET:(NSString *)URLString
                 headParameters:(NSDictionary*)headParameters
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param headParameters 请求head设置
 *  @param parameters     请求参数
 *  @param downLoadProgress 下载进度
 *  @param success          成功
 *  @param failure          失败
 *
 *  @return 返回请求对象
 */
- (void)GET:(NSString *)URLString
                 headParameters:(NSDictionary*)headParameters
                     parameters:(id)parameters
               DownloadProgress:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))downLoadProgress
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

/**
 *  下载图片
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *  @return 返回请求对象
 */
- (void)GETImage:(NSString *)URLString
                          parameters:(id)parameters
                             success:(void (^)( id responseObject))success
                             failure:(void (^)( NSError *error))failure;
/**
 *  下载图片
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param downLoadProgress 下载进度
 *  @param success    成功
 *  @param failure    失败
 *  @return 返回请求对象
 */
- (void)GETImage:(NSString *)URLString
                          parameters:(id)parameters
                    DownloadProgress:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))downLoadProgress
                             success:(void (^)( id responseObject))success
                             failure:(void (^)( NSError *error))failure;
/**
 *  http请求对象获取，单利
 *
 *  @return 返回当前请求对象
 */
+ (instancetype )sharedInstance;

- (void)cancelAllHTTPOperationsWithMethod;


@end








